home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume1 / torch / part03 < prev    next >
Encoding:
Internet Message Format  |  1993-04-28  |  51.2 KB

  1. From: mikew@wyse.wyse.com (Mike Wexler)
  2. Newsgroups: comp.sources.x
  3. Subject: v01i064:  torch: dialog utilities, Part03/04
  4. Message-ID: <1737@wyse.wyse.com>
  5. Date: 12 Oct 88 18:41:37 GMT
  6. Approved: mikew@wyse.com
  7.  
  8. Submitted-by:  gary@torch.UUCP (Gary Henderson)
  9. Posting-number: Volume 1, Issue 64
  10. Archive-name: torch/part03
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 3 (of 4)."
  19. # Contents:  gs.1 gs.c main.c misc.c textmode.c yorn.1
  20. # Wrapped by mikew@wyse on Wed Oct 12 11:38:41 1988
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'gs.1' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'gs.1'\"
  24. else
  25. echo shar: Extracting \"'gs.1'\" \(6048 characters\)
  26. sed "s/^X//" >'gs.1' <<'END_OF_FILE'
  27. X.TH GS 1 "3 October 1988" "X Version 11"
  28. X.SH NAME
  29. Xgs \- get a text string from a dialogue box
  30. X.SH SYNOPSIS
  31. X.B gs
  32. X[
  33. X.B \-z
  34. X] [ 
  35. X.B \-r width height
  36. X] [
  37. X.B \-t timeout
  38. X] [
  39. X.B \-n title
  40. X] [
  41. X.B \-standard X Toolkit options \.\.\.
  42. X] [
  43. X.B text to be displayed
  44. X]
  45. X.SH DESCRIPTION
  46. X.I Gs
  47. Xis a utility designed for use in shell scripts for obtaining short text
  48. Xresponses from users.
  49. X.PP
  50. X.I Gs
  51. Xopens a window containing a box to display the text passed on the command
  52. Xline.  If the
  53. X.B \-r
  54. Xoption is present, another box is created into which the user may enter a
  55. Xreply (the maximum number characters that may be entered is given by
  56. X\fIwidth\fPx\fIheight\fP fields from the
  57. X.B \-r
  58. Xoption).  The reply box allows simple character editing (such as cursor
  59. Xmovement, character insertion and deletion).  The window can be closed and any
  60. Xtext typed by the user sent to standard output by clicking the `Finished'
  61. Xbutton with the mouse.  The window is also closed and any text sent if a
  62. Xtimeout has been specified (see the
  63. X.B \-t
  64. Xoption) and this has been exceeded.
  65. X.PP
  66. X.I Gs
  67. Xcan take the following options:
  68. X.TP 8
  69. X.B \-z
  70. XNo Zoom.  \fIGs\fP will attempt to bypass the window manager and appear
  71. Ximmediately, rather than going through the window manager's placement and
  72. Xsizing scheme.
  73. X.PP
  74. X.TP 8
  75. X.B \-r \fIwidth\fP \fIheight\fP
  76. XA reply box of \fIwidth\fP characters wide and \fIheight\fP characters high
  77. Xwill be created (if the window manager or screen size allows).  The maximum
  78. Xnumber of characters the user may enter is always \fIwidth\fPx\fIheight\fP
  79. Xcharacters.  The text in the reply box may be scrolled if the box cannot be
  80. Xmade large enough or lots of short lines have been entered.
  81. X.TP 8
  82. X.B \-n \fItitle\fP \fRor\fP \-title \fItitle\fP
  83. XSpecifies the title for the \fIgs\fP window.  The default, if this option is
  84. Xnot supplied, is `Get string'.
  85. X.TP 8
  86. X.B \-t \fInumber\fP
  87. XSpecifies a timeout value (in seconds) in which the user must enter a reply.
  88. XIf the time limit is exceeded, any text already typed will be sent to \fgs\fP'
  89. Xstandard output and \fIgs\fP will exit.
  90. X.PP
  91. X\fIGs\fP additionally recognizes the following standard X Toolkit command
  92. Xline arguments:
  93. X.TP 8
  94. X.B \-bg \fIcolour\fP \fRor\fP \-background \fIcolour\fP
  95. XThis option specifies the colour to use for the background of the window and
  96. Xwidgets.  The default is `white.'
  97. X.TP 8
  98. X.B \-bd \fIcolour\fP \fRor\fP \-bordercolor \fIcolour\fP
  99. XThis option specifies the colour to use for the border of the main window.
  100. XThe default is `black.'
  101. X.TP 8
  102. X.B \-bw \fInumber\fP \fRor\fP \-borderwidth \fInumber\fP
  103. XThis option specifies the width in pixels of the border surrounding the main
  104. Xwindow. 
  105. X.TP 8
  106. X.B \-fg \fIcolour\fP \fRor\fP \-foreground \fIcolour\fP
  107. XThis option specifies the colour to use for the text.  The default
  108. Xis `black'.
  109. X.TP 8
  110. X.B \-fn \fIfont\fP
  111. XThis option specifies the font to be used for displaying the text warning
  112. Xmessage.  The default is `serif10'.
  113. X.TP 8
  114. X.B \-name \fIname\fP
  115. XThis option specifies the application name under which resources are to be
  116. Xobtained, rather than the default executable file name, `gs'.
  117. X.TP 8
  118. X.B \-geometry \fIgeometry\fP
  119. XThis option specifies the preferred size and position of the gs window; see
  120. X\fIX(1)\fP; 
  121. X.TP 8
  122. X.B \-display \fIdisplay\fP
  123. XThis option specifies the X server to contact; see \fIX(1)\fP.
  124. X.TP 8
  125. X.B \-xrm \fIresourcestring\fP
  126. XThis option specifies a resource string to be used.  This is especially
  127. Xuseful for setting resources that do not have separate command line options.
  128. X.SH "X DEFAULTS"
  129. X\fIGs\fP is implemented using the Athena widgets.  Each widget can
  130. Xindividually or in groups have various visual and operational aspects changed
  131. Xvia a `.Xdefaults' file on the client machine or the `RESOURCE_MANAGER'
  132. Xproperty on the server.  All widgets have a common set of resources
  133. X(background, backgroundPixmap, etc.) and resources unique to each type of
  134. Xwidget; a `command button' widget, for example, also has a cursor resource.
  135. XFor a full list see the document \fIX Toolkit Widgets - C Language X
  136. XInterface\fP. 
  137. X.PP
  138. XThe path names and types of all widgets used by \fIgs\fP are as follows:
  139. X.TP 8
  140. X.B "\fIXXX\fP.gsbox"
  141. XThe widget that is a child of root.  All the other widgets used by the gs
  142. Xbox are children or grand children of this widget. 
  143. X.TP 8
  144. X.B "\fIXXX\fP.gsbox.contents"
  145. XA form widget that manages the layout of the gs box.  Normally completely
  146. Xcovers the `gsbox' widget.
  147. X.TP 8
  148. X.B "\fIXXX\fP.gsbox.contents.message"
  149. XA widget to display and format the text message.
  150. X.TP 8
  151. X.B "\fIXXX\fP.gsbox.contents.Finished"
  152. XA command button widget that when clicked causes \fIgs\fP to write any text
  153. Xentered by the user to standard output and exit.
  154. X.TP 8
  155. X.B "\fIXXX\fP.gsbox.contents.reply"
  156. XA text widget where the user can type a reply.
  157. X.PP
  158. XAdditionally, the following item is also fetched from the resource database:
  159. X.TP 8
  160. X.B "backgroundPixmap.foreground"
  161. XOne of two colours (the other is the widget's background colour) required when
  162. Xconverting a bitmap file into a pixmap for use as the widget's background
  163. Xpixmap. 
  164. X.SH RETURN CODES
  165. X.IP
  166. X0 \- Termination via the tick box or the timeout value being exceeded.
  167. X.IP
  168. X2 \- Termination due to some internal error.
  169. X.SH ENVIRONMENT
  170. X.TP 8
  171. XDISPLAY - the default host and display number of the X server.
  172. X.TP 8
  173. XXENVIRONMENT - the name of the Xdefaults file to use (normally
  174. X$HOME/.Xdefaults). 
  175. X.SH EXAMPLES
  176. X.IP
  177. Xgs -r 40 1 Please enter the name of a file to edit
  178. X.PP
  179. XWill open an gs box with the title
  180. X.I Get string
  181. Xand containing a box displaying the text
  182. X.I Please enter the name of a file to edit
  183. Xand another box where the user may type upto 40 characters.
  184. X.SH FILES
  185. X$HOME/.Xdefaults
  186. X/usr/lib/X11/app-defaults/Xopentop
  187. X.SH SEE ALSO
  188. Xalert(1), yorn(1)
  189. X.SH BUGS
  190. X.PP
  191. XIf the font is too large or the message too long, the text will be clipped and
  192. Xthe window will have to be scrolled before the whole message may be read.
  193. X.PP
  194. XThe title may not be displayed if the window manager does not provide title
  195. Xbars around windows or the \fB\-z\fP option is used.
  196. X.SH AUTHOR
  197. XGary Henderson & Mark E. Howells, Torch Computers Ltd.
  198. END_OF_FILE
  199. if test 6048 -ne `wc -c <'gs.1'`; then
  200.     echo shar: \"'gs.1'\" unpacked with wrong size!
  201. fi
  202. # end of 'gs.1'
  203. fi
  204. if test -f 'gs.c' -a "${1}" != "-c" ; then 
  205.   echo shar: Will not clobber existing file \"'gs.c'\"
  206. else
  207. echo shar: Extracting \"'gs.c'\" \(7594 characters\)
  208. sed "s/^X//" >'gs.c' <<'END_OF_FILE'
  209. X/*
  210. XCopyright 1988 Torch Computers Ltd.
  211. X
  212. XPermission to use, copy, modify, and otherwise generally do what you like
  213. Xwith this software is hereby granted provided that the above copyright notice
  214. Xappears in all copies.
  215. X
  216. XTorch disclaims all warranties implied or expressed with regard to this
  217. Xsoftware.  In no event shall Torch be liable for any damages arising from
  218. Xthis use of software.
  219. X*/
  220. X
  221. X/********************************************************
  222. X*                            *
  223. X*  Title   Yorn, Gs and Alert                *
  224. X*                            *
  225. X*  File       : gs.c                    *
  226. X*  Author  : Gary Henderson                *
  227. X*  Date       : 29th Sep 1988                *
  228. X*  Purpose : The gs box widgets code.                    *
  229. X*                            *
  230. X*********************************************************/
  231. X
  232. X/*------Include files-----------------------------------*/
  233. X
  234. X#include <stdio.h>
  235. X#include <X11/Xlib.h>
  236. X#include <X11/Xos.h>
  237. X#include <X11/Xutil.h>
  238. X#include <X11/StringDefs.h>
  239. X#include <X11/Intrinsic.h>
  240. X#include <X11/Form.h>
  241. X#include <X11/Core.h>
  242. X#include <X11/Shell.h>
  243. X#include <X11/Command.h>
  244. X#include <X11/AsciiText.h>
  245. X
  246. X/*------Forward delarations-----------------------------*/
  247. X
  248. Xextern long time ();
  249. X
  250. X/*------Constants and macros----------------------------*/
  251. X
  252. X#define ALONX             ((root_width / 5 + rand () % 48))
  253. X#define ALONY             ((root_height / 5 + rand () % 48))
  254. X#define MESSAGE_WIDTH    40
  255. X#define EXTRA 6
  256. X
  257. X/*------Exported variables/functions--------------------*/
  258. X
  259. XWidget     gswidget;
  260. Xvoid     Finished ();
  261. X
  262. X/*------Imported variables/functions--------------------*/
  263. X
  264. Xextern Widget         a_widget;
  265. Xextern XFontStruct  *sysfont;
  266. Xextern unsigned int root_width, root_height;
  267. Xextern Display         *display;
  268. Xextern Window         root_window;
  269. Xextern int          screen_number;
  270. Xextern Screen         *screen;
  271. Xextern Boolean         zoom;
  272. Xextern int          lines, cols;
  273. Xextern char         *font_name;
  274. X
  275. X/*------Static variables--------------------------------*/
  276. X
  277. Xstatic Widget     button;
  278. Xstatic Widget     textwidget;
  279. Xstatic Widget     messagewidget;
  280. Xstatic char     *data;
  281. Xstatic int      length;
  282. X
  283. X/*
  284. X                            *****************
  285. X                            *        *
  286. X                            *    INITGS    *
  287. X                            *        *
  288. X                            *****************
  289. X-------------------------------------------------------------------------
  290. X| Initialise the widgets for the gs box.                                |
  291. X-------------------------------------------------------------------------
  292. X*/
  293. Xvoid InitGS (string, geometry)
  294. Xchar * string;
  295. Xchar * geometry;
  296. X{
  297. X    Arg args[20];
  298. X    Widget formwidget;
  299. X    int message_width, message_height;
  300. X    int char_width = (sysfont->max_bounds.width + 
  301. X                      sysfont->min_bounds.width) / 2;
  302. X    int char_height = (sysfont->ascent + sysfont->descent);
  303. X    int mx_offset, tx_offset;
  304. X    
  305. X    static XtCallbackRec ackbacks[] = {
  306. X        {Finished, NULL},
  307. X        {NULL, NULL},
  308. X    };
  309. X
  310. X#ifdef BSD
  311. X    (void) srand ((int) time ((long *) 0));
  312. X#endif BSD
  313. X
  314. X#if defined(UNISOFTV) || defined(SYSV)
  315. X    (void) srand ((unsigned int) time ((long *) 0));
  316. X#endif /* UNISOFTV || SYSV */
  317. X
  318. X    /* Its a popup */
  319. X
  320. X    XtSetArg (args[0], XtNx, ALONX);
  321. X    XtSetArg (args[1], XtNy, ALONY);
  322. X    XtSetArg (args[2], XtNgeometry, geometry);
  323. X    
  324. X    gswidget = XtCreatePopupShell ("gsbox", 
  325. X                                    zoom ? topLevelShellWidgetClass :
  326. X                           overrideShellWidgetClass, 
  327. X                    a_widget,
  328. X                    args,
  329. X                    geometry ? 3 : 2);
  330. X                    
  331. X    formwidget= XtCreateManagedWidget ("contents",
  332. X                                      formWidgetClass,
  333. X                      gswidget,
  334. X                      (ArgList) 0,
  335. X                      0);
  336. X
  337. X    XtSetArg (args[0], XtNhorizDistance, 4);
  338. X    XtSetArg (args[1], XtNvertDistance, 4);
  339. X    XtSetArg (args[2], XtNresizable, False);
  340. X    XtSetArg (args[3], XtNcallback, ackbacks);
  341. X    XtSetArg (args[4], XtNfont, sysfont);
  342. X    XtSetArg (args[5], XtNbottom, XtChainTop);
  343. X    XtSetArg (args[6], XtNtop, XtChainTop);
  344. X    XtSetArg (args[7], XtNleft, XtChainLeft);
  345. X    XtSetArg (args[8], XtNright, XtChainLeft);
  346. X    
  347. X    button = XtCreateManagedWidget("Finished",
  348. X                                    commandWidgetClass,
  349. X                    formwidget,
  350. X                    args,
  351. X                    9);
  352. X
  353. X    message_height = char_height + EXTRA;
  354. X
  355. X    if (strlen (string) < MESSAGE_WIDTH)
  356. X        message_width = strlen (string) * char_width + EXTRA;
  357. X    else
  358. X    {
  359. X        message_width = MESSAGE_WIDTH * char_width + EXTRA;
  360. X    message_height = char_height * (1 + strlen (string) / 
  361. X                                   MESSAGE_WIDTH) + EXTRA;
  362. X    }
  363. X
  364. X    if (cols * lines != 0)
  365. X    {
  366. X        if (cols * char_width + EXTRA > message_width)
  367. X    {
  368. X            mx_offset = ((cols * char_width + EXTRA) - message_width) / 2 + 4;
  369. X        tx_offset = 4;
  370. X    }
  371. X    else
  372. X    {
  373. X            mx_offset = 4;
  374. X            tx_offset = (message_width - (cols * char_width + EXTRA)) / 2 + 4;
  375. X    }
  376. X    }
  377. X    else
  378. X        mx_offset = 4;
  379. X
  380. X    XtSetArg (args[0], XtNhorizDistance, mx_offset);
  381. X    XtSetArg (args[1], XtNvertDistance, 4);
  382. X    XtSetArg (args[2], XtNresizable, True);
  383. X    XtSetArg (args[3], XtNeditType, XttextRead);
  384. X    XtSetArg (args[4], XtNstring, string);
  385. X    XtSetArg (args[5], XtNlength, strlen (string));
  386. X    XtSetArg (args[6], XtNtextOptions, scrollOnOverflow | wordBreak);
  387. X    XtSetArg (args[7], XtNbottom, XtRubber);
  388. X    XtSetArg (args[8], XtNtop, XtChainTop);
  389. X    XtSetArg (args[9], XtNleft, XtChainLeft);
  390. X    XtSetArg (args[10], XtNright, XtChainRight);
  391. X    XtSetArg (args[11], XtNfromVert, button);
  392. X    XtSetArg (args[12], XtNwidth, message_width);
  393. X    XtSetArg (args[13], XtNheight, message_height);
  394. X    XtSetArg (args[14], XtNfont, sysfont);
  395. X    
  396. X    messagewidget = XtCreateManagedWidget ("message", asciiStringWidgetClass, 
  397. X                                        formwidget, args, 15);
  398. X    if (lines * cols != 0)
  399. X    {
  400. X        data = XtMalloc ((length = lines * cols) + 2);
  401. X
  402. X        *data = '\0';
  403. X    
  404. X    XtSetArg (args[0], XtNhorizDistance, tx_offset);
  405. X        XtSetArg (args[1], XtNvertDistance, 4);
  406. X        XtSetArg (args[2], XtNresizable, False);
  407. X        XtSetArg (args[3], XtNeditType, XttextEdit);
  408. X        XtSetArg (args[4], XtNstring, data);
  409. X        XtSetArg (args[5], XtNlength, length);
  410. X        XtSetArg (args[6], XtNtextOptions, scrollOnOverflow | wordBreak | editable);
  411. X        XtSetArg (args[7], XtNbottom, XtChainBottom);
  412. X        XtSetArg (args[8], XtNtop, XtRubber);
  413. X        XtSetArg (args[9], XtNleft, XtChainLeft);
  414. X        XtSetArg (args[10], XtNright, XtChainRight);
  415. X        XtSetArg (args[11], XtNfromVert, messagewidget);
  416. X        XtSetArg (args[12], XtNwidth, cols * char_width + EXTRA);
  417. X        XtSetArg (args[13], XtNheight, lines * char_height + EXTRA);
  418. X        XtSetArg (args[14], XtNfont, sysfont);
  419. X    
  420. X        textwidget = XtCreateManagedWidget ("reply", asciiStringWidgetClass, 
  421. X                                                    formwidget, args, 15);
  422. X    }
  423. X    else
  424. X        length = 0, data = 0;
  425. X    
  426. X    XtRealizeWidget (gswidget);
  427. X}
  428. X
  429. X/*
  430. X                            *****************
  431. X                            *        *
  432. X                            *   FINISHED    *
  433. X                            *        *
  434. X                            *****************
  435. X-------------------------------------------------------------------------
  436. X| The 'Finished' button has been selected by the user.  Read the text    |
  437. X| widget's current text, print it on stdout and then exit.                |
  438. X-------------------------------------------------------------------------
  439. X*/
  440. X/*ARGSUSED*/
  441. Xvoid Finished (widget, client_data, call_data)
  442. XWidget widget;
  443. Xcaddr_t client_data,call_data;
  444. X{
  445. X    char * p;
  446. X    
  447. X    XtPopdown (gswidget);
  448. X
  449. X    if (length == 0)
  450. X        exit (0);
  451. X    
  452. X    /* Remove trailing spaces and make sure the string is terminated by
  453. X       a new line character */
  454. X       
  455. X    p = data + strlen (data);
  456. X
  457. X    if (strlen (data) != 0)
  458. X        p--;
  459. X    
  460. X    if (*p != '\n')
  461. X    {
  462. X        while (p > data && *p == ' ')
  463. X        p--;
  464. X
  465. X    if (*p == ' ')
  466. X        *p++ = '\n';
  467. X        else
  468. X        if (*p != '\n')
  469. X        {
  470. X        *++p = '\n';
  471. X        p++;
  472. X        }
  473. X    
  474. X    *p = '\0';
  475. X    }
  476. X        
  477. X    printf ("%s", data);
  478. X    exit (0);
  479. X}
  480. END_OF_FILE
  481. if test 7594 -ne `wc -c <'gs.c'`; then
  482.     echo shar: \"'gs.c'\" unpacked with wrong size!
  483. fi
  484. # end of 'gs.c'
  485. fi
  486. if test -f 'main.c' -a "${1}" != "-c" ; then 
  487.   echo shar: Will not clobber existing file \"'main.c'\"
  488. else
  489. echo shar: Extracting \"'main.c'\" \(13399 characters\)
  490. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  491. X/*
  492. XCopyright 1988 Torch Computers Ltd.
  493. X
  494. XPermission to use, copy, modify, and otherwise generally do what you like
  495. Xwith this software is hereby granted provided that the above copyright notice
  496. Xappears in all copies.
  497. X
  498. XTorch disclaims all warranties implied or expressed with regard to this
  499. Xsoftware.  In no event shall Torch be liable for any damages arising from
  500. Xthis use of software.
  501. X*/
  502. X
  503. X/********************************************************
  504. X*                            *
  505. X*  Title   Yorn, Gs and Alert                *
  506. X*                            *
  507. X*  File       : main.c                    *
  508. X*  Author  : Gary Henderson                *
  509. X*  Date       : 26th Sep 1988.                             *
  510. X*  Purpose : Decide what we are called (hence what      *
  511. X*            progame to act like), initialise the       *
  512. X*            toolkit, setup some global variables and    *
  513. X*            call the right code.                       *
  514. X*                            *
  515. X*********************************************************/
  516. X
  517. X/*------Include files-----------------------------------*/
  518. X
  519. X#include <stdio.h>
  520. X#include <X11/Xlib.h>
  521. X#include <X11/Xos.h>
  522. X#include <X11/Xutil.h>
  523. X#include <X11/StringDefs.h>
  524. X#include <X11/Intrinsic.h>
  525. X#include <X11/TopLevel.h>
  526. X#include <X11/Shell.h>
  527. X#include <X11/Core.h>
  528. X#include <X11/Label.h>
  529. X#include <X11/cursorfont.h>
  530. X
  531. X#include "classname.h"
  532. X
  533. X/*------Forward delarations-----------------------------*/
  534. X
  535. Xstatic void InitFontAndResources ();
  536. X
  537. X/*------Constants and macros----------------------------*/
  538. X
  539. X#define EXTRABIT    50    /* Extra amount added to new long string */
  540. X
  541. X/*------Exported variables/functions--------------------*/
  542. X
  543. XDisplay     *display;
  544. XWindow         root_window;
  545. XScreen         *screen;
  546. Xint         screen_number;
  547. XXFontStruct *sysfont;
  548. XWidget         a_widget;
  549. XCursor         arrow_cursor;
  550. Xunsigned int root_width, 
  551. X             root_height;
  552. XBoolean     zoom = True;              /* Flag to use override redirect
  553. X                                       (False, use override ) */
  554. Xint         cols = 0, 
  555. X            lines = 0,
  556. X         timeout = 0;
  557. Xchar         *title;
  558. Xint         is_gs;
  559. Xchar        *alertsym_name,         /* Various names of bitmap files */
  560. X            *yornsym_name,          /* if not null, use these in preference */
  561. X        *ticksym_name,          /* to the built-in ones. */
  562. X            *crosssym_name,
  563. X        *oksym_name;
  564. X
  565. Xchar         *progname;
  566. X        
  567. Xvoid        ReadWidgetColours ();
  568. Xvoid         Usage ();
  569. X
  570. X/*------Imported variables/functions--------------------*/
  571. X
  572. Xextern Widget     alertwidget;
  573. Xextern Widget     gswidget;
  574. Xextern void     Finished (), AddTimeout (), AddNewConverter ();
  575. Xextern void     Yorn (), Alert (), InitAlert (), InitGS ();
  576. X
  577. X/*------Static variables--------------------------------*/
  578. X
  579. Xstatic XrmOptionDescRec gscommand_options[] =
  580. X{
  581. X    {"-z", "*zoom", XrmoptionNoArg, (caddr_t) "False"},
  582. X    {"-r", "*columns", XrmoptionSepArg, (caddr_t) NULL},
  583. X    {"-n", "*gstitle", XrmoptionSepArg, (caddr_t) NULL},
  584. X    {"-t", "*gstimeout", XrmoptionSepArg, (caddr_t) NULL},
  585. X};
  586. X
  587. Xstatic XrmOptionDescRec alertcommand_options[] =
  588. X{
  589. X    {"-z", "*zoom", XrmoptionNoArg, (caddr_t) "False"},
  590. X};
  591. X
  592. X/*
  593. X                            *****************
  594. X                            *        *
  595. X                            *     MAIN    *
  596. X                            *        *
  597. X                            *****************
  598. X-------------------------------------------------------------------------
  599. X| Try to open the connection to the X server.  If OK initialise the     |
  600. X| toolkit, otherwise drop into text only mode.  If toolkit initialised, |
  601. X| setup some global variables, load up some resources and decide from    |
  602. X| our name what utility to act like.                                    |
  603. X-------------------------------------------------------------------------
  604. X*/
  605. Xint main (argc, argv)
  606. Xint argc;
  607. Xchar *argv[];
  608. X{
  609. X    Arg arglist [10];
  610. X    unsigned int dummy;
  611. X    Window dummy_window;
  612. X    char * message;
  613. X    char * geometry;
  614. X    int i, len, start_arg;
  615. X    int alert_comm_size = XtNumber (alertcommand_options);
  616. X    int gs_comm_size = XtNumber (gscommand_options);
  617. X    char * disp = NULL;
  618. X    
  619. X    /* Note our base name */
  620. X    
  621. X    if ((progname = rindex (argv[0], '/')) == 0)
  622. X        progname = argv[0];
  623. X    else
  624. X        progname++;
  625. X    
  626. X    is_gs = strcmp (progname, "gs") == 0;
  627. X
  628. X    /* See if the -display flag has been passed on the command line */
  629. X    
  630. X    for (i = 1;    i < argc; i++)
  631. X        if (strcmp (argv[i], "-display") == 0)
  632. X    {
  633. X        disp = argv[i + 1];
  634. X        break;
  635. X    }
  636. X
  637. X    /* Make sure server is up and running */
  638. X    
  639. X    if ((display = XOpenDisplay (disp)) == NULL)
  640. X    {
  641. X        /* Cannot open display, go into text mode */
  642. X        
  643. X    TextMode (argc, argv);
  644. X    }
  645. X
  646. X    XCloseDisplay (display);
  647. X    
  648. X    AddNewConverter ();
  649. X    
  650. X    /* Initialise the toolkit */
  651. X
  652. X    if ((a_widget = XtInitialize ("temp", CLASSNAME, 
  653. X                    is_gs ? gscommand_options : alertcommand_options,
  654. X             is_gs ? gs_comm_size : alert_comm_size,
  655. X            &argc, argv)) == NULL)
  656. X    {
  657. X        (void) fprintf (stderr, "%s: Failed to initialise X toolkit\n", progname);
  658. X    TextMode (argc, argv);
  659. X    }
  660. X    
  661. X    display = XtDisplay (a_widget);
  662. X    root_window = DefaultRootWindow (display);
  663. X    screen_number = DefaultScreen (display);
  664. X    screen = DefaultScreenOfDisplay (display);
  665. X
  666. X    /* Find out size of root window */
  667. X    
  668. X    if (!XGetGeometry (display, 
  669. X                       root_window,
  670. X               &dummy_window, 
  671. X               &dummy, 
  672. X               &dummy, 
  673. X               &root_width, 
  674. X               &root_height,
  675. X               &dummy, 
  676. X               &dummy))
  677. X    {
  678. X        /* If couldn't obtain size of root window, use the macros instead */
  679. X    
  680. X    root_width = WidthOfScreen (screen);
  681. X    root_height = HeightOfScreen (screen);
  682. X    }
  683. X
  684. X    /* Read what font to use and some other resource values */
  685. X
  686. X    InitFontAndResources ();
  687. X
  688. X    /* Check the number of command line options are OK */
  689. X    
  690. X    if ((!is_gs && argc < 3) || 
  691. X        (is_gs && ((cols != 0 && argc < 3) || 
  692. X    (cols == 0 && argc < 2))))
  693. X        Usage ();
  694. X
  695. X    /* If the toplevel widget has been given a geometry string pass it on
  696. X       to the other toplevel widgets */
  697. X       
  698. X    XtSetArg (arglist[0], XtNgeometry, &geometry);
  699. X    XtGetValues (a_widget, arglist, 1);
  700. X
  701. X    /* We are called 'gs', so start acting like it */
  702. X    
  703. X    if (is_gs)
  704. X    {
  705. X        /* If the -r flag has been given then the first arg in the argv list
  706. X              must be the number of lines */
  707. X       
  708. X        if (cols == 0)
  709. X            start_arg = 0;
  710. X        else
  711. X        {
  712. X            start_arg = 1;
  713. X
  714. X        if (sscanf (argv[1], "%d", &lines) != 1)
  715. X            Usage ();
  716. X        }
  717. X    
  718. X        /* Message may have been given as lots of seperate arguments.
  719. X              Copy them into one long string */
  720. X
  721. X        len = strlen (argv[start_arg + 1]) + 1;
  722. X        message = XtMalloc (len);
  723. X    
  724. X        (void) strcpy (message, argv[start_arg + 1]);
  725. X
  726. X        for (i = start_arg + 2; i < argc; i++)
  727. X        {
  728. X            if (strlen (argv[i]) + strlen (message) + 2 > len)
  729. X            /* Need more space for the string */
  730. X                message = XtRealloc (message, 
  731. X                             len = len + strlen (argv[i]) + 2);
  732. X        
  733. X        (void) strcat (message, " ");
  734. X            (void) strcat (message, argv[i]);
  735. X        }
  736. X
  737. X    /* Initialise the gs widgets */
  738. X    
  739. X        InitGS (message, geometry);
  740. X    
  741. X        XtSetArg (arglist[0], XtNtitle, title);
  742. X        XtSetValues (gswidget, arglist, 1);
  743. X
  744. X        /* Add an event handler to set a timer going on the first
  745. X       MapNotify event if a timeout has been specified for gs */
  746. X    
  747. X    if (timeout)
  748. X            XtAddEventHandler (gswidget, 
  749. X                           StructureNotifyMask, 
  750. X                   False, 
  751. X                   AddTimeout, 
  752. X                               (caddr_t) NULL);
  753. X                   
  754. X        XtPopup (gswidget, XtGrabExclusive);
  755. X    XDefineCursor (display, XtWindow (gswidget), arrow_cursor);
  756. X    }
  757. X    else
  758. X    {
  759. X        /* Initialise the widgets for the yorn and alert boxes */
  760. X    
  761. X    InitAlert (geometry);
  762. X    
  763. X        XtSetArg (arglist[0], XtNtitle, argv[1]);
  764. X        XtSetValues (alertwidget, arglist, 1);
  765. X
  766. X        /* Message may have been given as lots of seperate arguments.
  767. X              Copy them into one long string */
  768. X
  769. X        len = strlen (argv[2]) + EXTRABIT + 1;
  770. X        message = XtMalloc (len);
  771. X    
  772. X        (void) strcpy (message, argv[2]);
  773. X
  774. X        for (i = 3; i < argc; i++)
  775. X        {
  776. X            if (strlen (argv[i]) + strlen (message) + 2 > len)
  777. X            /* Need more space for the string */
  778. X                message = XtRealloc (message, 
  779. X                             len = len + strlen (argv[i]) +
  780. X                                       EXTRABIT + 2);
  781. X        (void) strcat (message, " ");
  782. X            (void) strcat (message, argv[i]);
  783. X        }
  784. X    
  785. X        /* If we are called 'alert' act like alert otherwise act like yorn */
  786. X    
  787. X    if (strcmp (progname, "alert") == 0)
  788. X            Alert (message);
  789. X        else
  790. X            Yorn (message);
  791. X    }
  792. X    
  793. X    /* Wait for events to arrive and act on them */
  794. X    
  795. X    XtMainLoop ();
  796. X}
  797. X
  798. X/*
  799. X                            *****************
  800. X                            *        *
  801. X                            *  ADDTIMEOUT    *
  802. X                            *        *
  803. X                            *****************
  804. X-------------------------------------------------------------------------
  805. X| Set a timer going on the first MapNotify event to be received from the|
  806. X| server.                                                               |
  807. X-------------------------------------------------------------------------
  808. X*/
  809. X/*ARGSUSED*/
  810. Xvoid AddTimeout (widget, client_data, event)
  811. XWidget widget;
  812. Xcaddr_t client_data;
  813. XXMapEvent * event;
  814. X{
  815. X    static int set = False;
  816. X    
  817. X    if (!set && event->type == MapNotify)
  818. X    {
  819. X        set = True;
  820. X    
  821. X    /* Add a dummy timeout value to stop a core dump with an early
  822. X       X11R2 toolkit issue */
  823. X       
  824. X    XtAddTimeOut ((unsigned long) 0xffffffff, Finished, (caddr_t) NULL);
  825. X        XtAddTimeOut ((unsigned long) (timeout * 1000), Finished, 
  826. X                                                        (caddr_t) NULL);
  827. X    }
  828. X}
  829. X
  830. X/*
  831. X                            *****************
  832. X                            *        *
  833. X                            *INITFONTANDRESOURCES*
  834. X                            *        *
  835. X                            *****************
  836. X-------------------------------------------------------------------------
  837. X| Looks up default font to use from toolkit database, loads it  and     |
  838. X| fills in a pointer to the font's structure.                              |
  839. X| and look up the icon height                        |
  840. X-------------------------------------------------------------------------
  841. X*/
  842. Xstatic void InitFontAndResources ()
  843. X{
  844. X    static char * sfont;
  845. X    static Boolean truezoom = True;
  846. X    static int zero = 0;
  847. X    static Cursor left_ptr;
  848. X    
  849. X    static XtResource resources[] = {
  850. X        {XtNfont, XtCFont, XtRString, (Cardinal) sizeof (char *),
  851. X     (Cardinal) &sfont, XtRString, (caddr_t) NULL},
  852. X        
  853. X        {XtNcursor, XtCCursor, XtRCursor, sizeof (Cursor),
  854. X     (Cardinal) &arrow_cursor, XtRCursor, (caddr_t) &left_ptr},
  855. X        
  856. X    {"zoom", "Zoom", XtRBoolean, (Cardinal) sizeof (Boolean),
  857. X     (Cardinal) &zoom, XtRBoolean, (caddr_t) &truezoom},
  858. X    
  859. X    {"columns", "Columns", XtRInt, (Cardinal) sizeof (int),
  860. X     (Cardinal) &cols, XtRInt, (caddr_t) &zero},
  861. X
  862. X    {"gstimeout", "Timeout", XtRInt, (Cardinal) sizeof (int),
  863. X     (Cardinal) &timeout, XtRInt, (caddr_t) 0},
  864. X
  865. X    {"gstitle", "Title", XtRString, (Cardinal) sizeof (char *),
  866. X     (Cardinal) &title, XtRString, (caddr_t) "Get String"},
  867. X
  868. X    {"alertsym", "Alertsym", XtRString, (Cardinal) sizeof (char *),
  869. X     (Cardinal) &alertsym_name, XtRString, (caddr_t) 0},
  870. X
  871. X    {"yornsym", "Yornsym", XtRString, (Cardinal) sizeof (char *),
  872. X     (Cardinal) &yornsym_name, XtRString, (caddr_t) 0},
  873. X    
  874. X    {"ticksym", "Ticksym", XtRString, (Cardinal) sizeof (char *),
  875. X     (Cardinal) &ticksym_name, XtRString, (caddr_t) 0},
  876. X
  877. X    {"crosssym", "Crosssym", XtRString, (Cardinal) sizeof (char *),
  878. X     (Cardinal) &crosssym_name, XtRString, (caddr_t) 0},
  879. X
  880. X    {"oksym", "Oksym", XtRString, (Cardinal) sizeof (char *),
  881. X     (Cardinal) &oksym_name, XtRString, (caddr_t) 0},
  882. X    };
  883. X    
  884. X    sysfont = (XFontStruct *) NULL;
  885. X    left_ptr = XtGetCursor (display, XC_left_ptr);
  886. X    
  887. X    XtGetApplicationResources (a_widget, (caddr_t) 0, resources, 
  888. X                                                XtNumber (resources), NULL, 0);
  889. X
  890. X    /* If no resource (-font or -fn) specified use default font (serif10) */
  891. X    
  892. X    if (sfont == NULL)
  893. X        sysfont = XLoadQueryFont (display, "serif10");
  894. X    else
  895. X        sysfont = XLoadQueryFont (display, sfont);
  896. X    
  897. X    /* If one of the fonts don't exist, use fixed.  If that isn't there
  898. X       we've had it */
  899. X       
  900. X    if (sysfont == NULL)
  901. X    sysfont = XLoadQueryFont (display, "fixed");
  902. X    
  903. X    if (sysfont == NULL)
  904. X    {
  905. X    (void) fprintf (stderr, "%s: Suitable font cannot be found - giving up.",
  906. X                        progname);
  907. X        exit (2);
  908. X    }
  909. X}
  910. X
  911. X/*
  912. X                            *****************
  913. X                            *        *
  914. X                            *READWIDGETCOLOURS*
  915. X                            *        *
  916. X                            *****************
  917. X-------------------------------------------------------------------------
  918. X| Read a widget's background and foreground (if it has one) colours.    |
  919. X-------------------------------------------------------------------------
  920. X*/
  921. X
  922. Xvoid ReadWidgetColours (widget, fore, back)
  923. XWidget widget;
  924. XPixel *fore, *back;
  925. X{
  926. X    Arg args[2];
  927. X    
  928. X    /* Set up some defaults just in case we can't read any values */
  929. X    
  930. X    *fore = BlackPixel (display, screen_number);
  931. X    *back = WhitePixel (display, screen_number);
  932. X    
  933. X    XtSetArg (args[0], XtNforeground, fore);
  934. X    XtSetArg (args[1], XtNbackground, back);
  935. X
  936. X    XtGetValues (widget, args, 2);
  937. X}
  938. X
  939. X/*
  940. X                            *****************
  941. X                            *        *
  942. X                            *     USAGE    *
  943. X                            *        *
  944. X                            *****************
  945. X-------------------------------------------------------------------------
  946. X| Too few command line arguments supplied, print out a usage string and |
  947. X| exit.                                                                    |
  948. X-------------------------------------------------------------------------
  949. X*/
  950. Xvoid Usage ()
  951. X{
  952. X    if (is_gs)
  953. X        (void) fprintf (stderr, "%s: Usage: %s [-z] [-r cols lines] [-n title] [-t seconds] message\n", 
  954. X                        progname, progname);
  955. X    else
  956. X        (void) fprintf (stderr, "%s: Usage: %s [-z] title message\n", progname, progname);
  957. X    
  958. X    exit (2);
  959. X}
  960. END_OF_FILE
  961. if test 13399 -ne `wc -c <'main.c'`; then
  962.     echo shar: \"'main.c'\" unpacked with wrong size!
  963. fi
  964. # end of 'main.c'
  965. fi
  966. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  967.   echo shar: Will not clobber existing file \"'misc.c'\"
  968. else
  969. echo shar: Extracting \"'misc.c'\" \(5047 characters\)
  970. sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  971. X/*
  972. XCopyright 1988 Torch Computers Ltd.
  973. X
  974. XPermission to use, copy, modify, and otherwise generally do what you like
  975. Xwith this software is hereby granted provided that the above copyright notice
  976. Xappears in all copies.
  977. X
  978. XTorch disclaims all warranties implied or expressed with regard to this
  979. Xsoftware.  In no event shall Torch be liable for any damages arising from
  980. Xthis use of software.
  981. X*/
  982. X
  983. X/********************************************************
  984. X*                            *
  985. X*  Title   Yorn, Gs and Alert.                            *
  986. X*                            *
  987. X*  File       : misc.c                    *
  988. X*  Author  : Gary Henderson                             *
  989. X*  Date       : 23rd Aug 1988                *
  990. X*  Purpose : String to pixmap converter so user can     *
  991. X*            specify background bitmaps for widgets.     *
  992. X*                            *
  993. X*********************************************************/
  994. X
  995. X/*------Include files-----------------------------------*/
  996. X
  997. X#include <stdio.h>
  998. X#include <X11/Xlib.h>
  999. X#include <X11/IntrinsicP.h>
  1000. X#include <X11/Convert.h>
  1001. X#include <X11/StringDefs.h>
  1002. X
  1003. X/*------Forward delarations-----------------------------*/
  1004. X
  1005. X/*------Constants and macros----------------------------*/
  1006. X
  1007. X/*------Exported variables/functions--------------------*/
  1008. X
  1009. Xvoid AddNewConverter ();
  1010. X
  1011. X/*------Imported variables/functions--------------------*/
  1012. X
  1013. X/*------Static variables--------------------------------*/
  1014. X
  1015. X/*
  1016. X                            *****************
  1017. X                            *        *
  1018. X                            *CVTSTRINGTOPIXMAP*
  1019. X                            *        *
  1020. X                            *****************
  1021. X-------------------------------------------------------------------------
  1022. X| Convert the given string (taken to be the path name of a bitmap file)    |
  1023. X| into a pixmap.  This is so the user can specify background pixmaps    |
  1024. X| for widgets from a .Xdefaults file.                                    |
  1025. X-------------------------------------------------------------------------
  1026. X*/
  1027. Xstatic void CvtStringToPixmap (args, num_args, fromVal, toVal)
  1028. XXrmValuePtr args;
  1029. XCardinal * num_args;
  1030. XXrmValuePtr fromVal;
  1031. XXrmValuePtr toVal;
  1032. X{
  1033. X    static Pixmap pixmap;
  1034. X    static Pixel fore_pixel;
  1035. X    static XtResource pixmap_resources[] = {
  1036. X        {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
  1037. X     (Cardinal) &fore_pixel, XtRString, "Black"},
  1038. X    };
  1039. X    
  1040. X    unsigned int width, height;
  1041. X    int result;
  1042. X    Pixmap temp;
  1043. X    XGCValues gcvalues;
  1044. X    GC gc;
  1045. X    Screen * screen;
  1046. X    Cardinal depth;
  1047. X    Pixel back_pixel;
  1048. X    Widget widget;
  1049. X    
  1050. X    if (*num_args != 4)
  1051. X        return;
  1052. X
  1053. X    widget = (Widget) args[0].addr;
  1054. X    screen = *((Screen **) args[1].addr);
  1055. X    
  1056. X    /* So much for doing things properly; if you try to get the widget's
  1057. X       depth with the following code: 
  1058. X            depth = *((Cardinal *) args[2].addr);
  1059. X
  1060. X       you always read zero !  So for the time been, assume the widget has
  1061. X       the same depth as the root window */
  1062. X
  1063. X    depth = PlanesOfScreen (screen);
  1064. X    back_pixel = *((Pixel *) args[3].addr);
  1065. X
  1066. X    result = XReadBitmapFile (DisplayOfScreen (screen),
  1067. X                              RootWindowOfScreen (screen),
  1068. X                  (char *) fromVal->addr,
  1069. X                          &width, 
  1070. X                  &height, 
  1071. X                  &temp, 
  1072. X                  (int *) 0,
  1073. X                  (int *) 0);
  1074. X
  1075. X    if (result != BitmapSuccess)
  1076. X        return;
  1077. X    else
  1078. X    {
  1079. X    pixmap = XCreatePixmap (DisplayOfScreen (screen),
  1080. X                            RootWindowOfScreen (screen),
  1081. X                width,
  1082. X                height, 
  1083. X                depth);
  1084. X        
  1085. X    /* Need two colours when converting a bitmap into a pixmap.  The
  1086. X       background pixel value is easy, but the foreground requires a bit
  1087. X       more work to get hold of */
  1088. X       
  1089. X    gcvalues.background = back_pixel;
  1090. X    
  1091. X    XtGetSubresources (widget, 
  1092. X                       (caddr_t) 0,
  1093. X               XtNbackgroundPixmap,
  1094. X               XtCPixmap,
  1095. X                           pixmap_resources,
  1096. X               XtNumber (pixmap_resources),
  1097. X               (ArgList) 0,
  1098. X               0);
  1099. X
  1100. X    gcvalues.foreground = fore_pixel;
  1101. X    
  1102. X    gc = XCreateGC (DisplayOfScreen (screen),
  1103. X                    pixmap,
  1104. X            GCForeground | GCBackground,
  1105. X            &gcvalues);
  1106. X
  1107. X    XCopyPlane (DisplayOfScreen (screen),
  1108. X                temp, 
  1109. X            pixmap, 
  1110. X            gc, 
  1111. X            0, 
  1112. X            0, 
  1113. X            width, 
  1114. X            height, 
  1115. X                0, 
  1116. X            0, 
  1117. X            1l);
  1118. X        
  1119. X    XFreePixmap (DisplayOfScreen (screen), temp);
  1120. X        XFreeGC (DisplayOfScreen (screen), gc);
  1121. X    }
  1122. X
  1123. X    toVal->addr = (caddr_t) &pixmap;
  1124. X    toVal->size = sizeof (Pixmap);
  1125. X}
  1126. X
  1127. X/*
  1128. X                            *****************
  1129. X                            *        *
  1130. X                            *ADDNEWCONVERTER*
  1131. X                            *        *
  1132. X                            *****************
  1133. X-------------------------------------------------------------------------
  1134. X| Install the string-to-pixmap converter into the toolkit's current list|
  1135. X| of converters.                                                        |
  1136. X-------------------------------------------------------------------------
  1137. X*/
  1138. Xvoid AddNewConverter ()
  1139. X{
  1140. X    static XtConvertArgRec pixmapConvertArgs[] = {
  1141. X        {XtBaseOffset, (caddr_t) 0, sizeof (Widget)},
  1142. X    {XtBaseOffset, (caddr_t) XtOffset (Widget, core.screen), 
  1143. X     sizeof (Screen *)},
  1144. X        {XtBaseOffset, (caddr_t) XtOffset (Widget, core.depth), 
  1145. X     sizeof (Cardinal)},
  1146. X    {XtBaseOffset, (caddr_t) XtOffset (Widget, core.background_pixel),
  1147. X     sizeof (Pixel)},
  1148. X    };
  1149. X
  1150. X    XtAddConverter (XtRString, XtRPixmap, CvtStringToPixmap,
  1151. X                    pixmapConvertArgs, XtNumber (pixmapConvertArgs));
  1152. X}
  1153. END_OF_FILE
  1154. if test 5047 -ne `wc -c <'misc.c'`; then
  1155.     echo shar: \"'misc.c'\" unpacked with wrong size!
  1156. fi
  1157. # end of 'misc.c'
  1158. fi
  1159. if test -f 'textmode.c' -a "${1}" != "-c" ; then 
  1160.   echo shar: Will not clobber existing file \"'textmode.c'\"
  1161. else
  1162. echo shar: Extracting \"'textmode.c'\" \(9705 characters\)
  1163. sed "s/^X//" >'textmode.c' <<'END_OF_FILE'
  1164. X/*
  1165. XCopyright 1988 Torch Computers Ltd.
  1166. X
  1167. XPermission to use, copy, modify, and otherwise generally do what you like
  1168. Xwith this software is hereby granted provided that the above copyright notice
  1169. Xappears in all copies.
  1170. X
  1171. XTorch disclaims all warranties implied or expressed with regard to this
  1172. Xsoftware.  In no event shall Torch be liable for any damages arising from
  1173. Xthis use of software.
  1174. X*/
  1175. X
  1176. X/********************************************************
  1177. X*                            *
  1178. X*  Title   Yorn, Gs and Alert                *
  1179. X*                            *
  1180. X*  File       : textmode.c                    *
  1181. X*  Author  : Gary Henderson                *
  1182. X*  Date       : 26th Sep 1988.                *
  1183. X*  Purpose : Terminal versions of above programs, in     *
  1184. X*            connection to server cannot be opened.     *
  1185. X*                            *
  1186. X*********************************************************/
  1187. X
  1188. X/*------Include files-----------------------------------*/
  1189. X
  1190. X#include <stdio.h>
  1191. X#include <signal.h>
  1192. X#include <errno.h>
  1193. X
  1194. X#if defined(SYSV) || defined(UNISOFTV)
  1195. X#include <termio.h>
  1196. X#endif SYSV
  1197. X
  1198. X#ifdef BSD
  1199. X#include <sgtty.h>
  1200. X#include <setjmp.h>
  1201. X#endif BSD
  1202. X
  1203. X/*------Forward delarations-----------------------------*/
  1204. X
  1205. X/*------Constants and macros----------------------------*/
  1206. X
  1207. X/*------Exported variables/functions--------------------*/
  1208. X
  1209. X/*------Imported variables/functions--------------------*/
  1210. X
  1211. Xextern int is_gs;
  1212. Xextern int cols, lines;
  1213. Xextern char * progname;
  1214. Xextern int errno;
  1215. Xextern int timeout;
  1216. Xextern void Usage ();
  1217. X
  1218. X/*------Static variables--------------------------------*/
  1219. X
  1220. Xstatic int size_args, title_arg, seconds_arg;
  1221. X
  1222. Xstatic int set = -1;
  1223. X
  1224. X#ifdef SYSV
  1225. Xstatic int (*old_sig[SIGPWR + 1])();
  1226. Xstatic struct termio term_settings, term;
  1227. X#endif SYSV
  1228. X
  1229. X#ifdef UNISOFTV
  1230. Xstatic int (*old_sig[SIGIO + 1])();
  1231. Xstatic struct termio term_settings, term;
  1232. X#endif UNISOFTV
  1233. X
  1234. X#ifdef BSD
  1235. Xstatic int (*old_sig[SIGUSR2 + 1])();
  1236. Xstatic struct sgttyb term_settings, term;
  1237. Xstatic jmp_buf env;
  1238. X#endif BSD
  1239. X
  1240. Xstatic struct options {
  1241. X    char * name;
  1242. X    int args;
  1243. X    int * addr;
  1244. X} opts[] = {
  1245. X    {"-z", 0, 0},
  1246. X    {"-r", 2, &size_args},
  1247. X    {"-n", 1, &title_arg},
  1248. X    {"-t", 1, &seconds_arg},
  1249. X    {"-display", 1, 0},
  1250. X    {"-font", 1, 0},
  1251. X    {"-fn", 1, 0},
  1252. X    {"-fg", 1, 0},
  1253. X    {"-bg", 1, 0},
  1254. X};
  1255. X
  1256. Xstatic int AlarmCall ();
  1257. Xstatic int alarm_gone_off = 0;
  1258. Xstatic int ResetTerm ();
  1259. X
  1260. X/*
  1261. X                            *****************
  1262. X                            *        *
  1263. X                            *   TEXTMODE    *
  1264. X                            *        *
  1265. X                            *****************
  1266. X-------------------------------------------------------------------------
  1267. X| Hmmm, the connection to the X server could not be made.  Just to be    |
  1268. X| nice, give the user a terminal version of the program he/she asked for|
  1269. X| (useful if the utility is in a Unix start up shell script and the     |
  1270. X| the server failed to start up for some reason).                       |
  1271. X-------------------------------------------------------------------------
  1272. X*/
  1273. XTextMode (argc, argv)
  1274. Xint argc;
  1275. Xchar ** argv;
  1276. X{
  1277. X    register struct options * parse;
  1278. X    int max_arg = 1;
  1279. X    int i, j;
  1280. X    char c;
  1281. X
  1282. X    /* Parse options (the toolkit can't parse them without a connection to
  1283. X       the server */
  1284. X    
  1285. X    for (i = 1; i < argc; i++)
  1286. X        for (j = 0, parse = opts; j < sizeof (opts) / sizeof (opts[0]); 
  1287. X                                                            j++, parse++)
  1288. X        if (strcmp (parse->name, argv[i]) == 0)
  1289. X        {
  1290. X            if (i + parse->args >= argc)
  1291. X            Usage ();
  1292. X
  1293. X        if (i + parse->args + 1 >= max_arg)
  1294. X            max_arg = i + parse->args + 1;
  1295. X
  1296. X        if (parse->addr)
  1297. X            *(parse->addr) = i + 1;
  1298. X
  1299. X        i += parse->args;
  1300. X
  1301. X        break;
  1302. X        }
  1303. X
  1304. X    if ((is_gs && argc - max_arg < 1) || (!is_gs && argc - max_arg < 2))
  1305. X        Usage ();
  1306. X
  1307. X    if (is_gs)
  1308. X    {
  1309. X    /* We are called 'gs', so act like gs.  Print out the title and 
  1310. X       the message... */
  1311. X    if (title_arg)
  1312. X        (void) fprintf (stderr, "\t%s\n", argv[title_arg]);
  1313. X
  1314. X    for (i = max_arg; i < argc; i++)
  1315. X        (void) fprintf (stderr, "%s ", argv[i]);
  1316. X
  1317. X    (void) fprintf (stderr, "\n");
  1318. X
  1319. X    /* ...find out if a timeout is required... */
  1320. X    
  1321. X    if (!seconds_arg || sscanf (argv[seconds_arg], "%d", &timeout) != 1 ||
  1322. X        timeout < 1)
  1323. X        timeout = 0;
  1324. X        
  1325. X    /* ...and the size of the reply from the user. */
  1326. X    
  1327. X    if (size_args)
  1328. X    {
  1329. X        if (sscanf (argv[size_args], "%d", &cols) != 1 ||
  1330. X            sscanf (argv[size_args + 1], "%d", &lines) != 1)
  1331. X
  1332. X            cols = lines = 0;
  1333. X    }
  1334. X    else
  1335. X        cols = lines = 0;
  1336. X
  1337. X    if (cols * lines <= 0)
  1338. X    {
  1339. X        /* Negative or zero length reply required from user.  If there's
  1340. X           a timeout wait for it to go off, otherwise... */
  1341. X        if (timeout)
  1342. X        {
  1343. X            (void) signal (SIGALRM, AlarmCall);
  1344. X            (void) alarm ((unsigned int) timeout);
  1345. X            
  1346. X        while (!alarm_gone_off)
  1347. X            pause ();
  1348. X        }
  1349. X        else
  1350. X        {
  1351. X            /* ...ask the user to press RETURN */
  1352. X        
  1353. X        (void) fprintf (stderr, "(Press RETURN to continue)");
  1354. X        (void) fflush (stderr);
  1355. X            
  1356. X        do
  1357. X            {
  1358. X            } while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
  1359. X                     (j == 1 && c != '\n')); 
  1360. X        }
  1361. X        
  1362. X        exit (0);
  1363. X    }
  1364. X    
  1365. X    /* A positive length reply is required from the user, ask for one... */
  1366. X
  1367. X    i = 0;
  1368. X
  1369. X    (void) fprintf (stderr, "(Please type in your reply and press RETURN)\n\
  1370. X\nEnter> ");
  1371. X    (void) fflush (stderr);
  1372. X    
  1373. X    /* ...set a timer going if a timeout is required... */
  1374. X    
  1375. X    if (timeout)
  1376. X    {
  1377. X        (void) signal (SIGALRM, AlarmCall);
  1378. X        (void) alarm ((unsigned int) timeout);
  1379. X    }
  1380. X    
  1381. X#ifdef BSD
  1382. X        if (setjmp (env) == 0)
  1383. X    {
  1384. X#endif BSD
  1385. X        /* ...and read in the reply and send it to stdout. */
  1386. X    
  1387. X    do
  1388. X    {
  1389. X        do
  1390. X        {
  1391. X            } while (!alarm_gone_off && ((j = read (0, &c, 1)) == -1 && 
  1392. X                                                        errno == EINTR));
  1393. X        if (j == 1 && i++ < cols * lines && c != '\n')
  1394. X            (void) putchar (c);
  1395. X
  1396. X    } while (j == 1 && c != '\n' && !alarm_gone_off);
  1397. X#ifdef BSD
  1398. X    }
  1399. X#endif BSD    
  1400. X
  1401. X    if (i)
  1402. X        (void) printf ("\n");
  1403. X        
  1404. X    exit (0);
  1405. X    }
  1406. X
  1407. X    /* Yorn or alert.  Print out the message... */
  1408. X    
  1409. X    (void) printf ("\t%s\n", argv[max_arg]);
  1410. X    
  1411. X    for (i = max_arg + 1; i < argc; i++)
  1412. X        (void) printf ("%s ", argv[i]);
  1413. X
  1414. X    if (strcmp ("alert", progname) == 0)
  1415. X    {
  1416. X        /* ...if we are alert, ask the user to press RETURN when he/she has
  1417. X       read the message... */
  1418. X       
  1419. X    (void) printf ("\07\n(Press RETURN to continue) ");
  1420. X        
  1421. X    (void) fflush (stdout);
  1422. X    
  1423. X    do
  1424. X    {
  1425. X    } while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
  1426. X                 (j == 1 && c != '\n')); 
  1427. X
  1428. X    exit (0);
  1429. X    }
  1430. X    else
  1431. X    {
  1432. X        /* ...otherwise must be yorn.  Trap most signals (so the terminal state
  1433. X       can be reset before we get killed off)... */
  1434. X       
  1435. X    (void) printf ("(y/n) ");
  1436. X
  1437. X    (void) fflush (stdout);
  1438. X    
  1439. X    for (i = SIGHUP; i < SIGALRM; i++)
  1440. X        old_sig[i] = signal (i, ResetTerm);
  1441. X
  1442. X#ifdef SYSV
  1443. X        for (i = SIGTERM; i <= SIGPWR; i++)
  1444. X        old_sig[i] = signal (i, ResetTerm);
  1445. X#endif SYSV
  1446. X
  1447. X#ifdef UNISOFTV
  1448. X        for (i = SIGTERM; i <= SIGIO; i++)
  1449. X        old_sig[i] = signal (i, ResetTerm);
  1450. X#endif UNISOFTV
  1451. X
  1452. X    /* ...fiddle the terminal to give one key press at a time and convert
  1453. X       upper-case to lower-case... */
  1454. X
  1455. X#if defined(SYSV) || defined(UNISOFTV)
  1456. X    if ((set = ioctl (0, TCGETA, &term_settings)) == 0)
  1457. X    {
  1458. X#ifdef UNISOFTV
  1459. X        blt ((char *) &term, (char *) &term_settings, 
  1460. X                                                sizeof (struct termio));
  1461. X#else
  1462. X        (void) memcpy ((char *) &term, (char *) &term_settings, 
  1463. X                                                sizeof (struct termio));
  1464. X#endif UNISOFTV
  1465. X
  1466. X        term.c_lflag &= ~ICANON;
  1467. X        term.c_iflag |= IUCLC;
  1468. X        
  1469. X        term.c_cc[4] = 1;
  1470. X        term.c_cc[5] = 255;
  1471. X
  1472. X        (void) ioctl (0, TCSETA, &term);
  1473. X    }
  1474. X#endif SYSV
  1475. X
  1476. X#ifdef BSD
  1477. X    for (i = SIGTERM; i <= SIGUSR2; i++)
  1478. X        old_sig[i] = signal (i, ResetTerm);
  1479. X        
  1480. X    if ((set = ioctl (0, TIOCGETP, &term_settings)) == 0)
  1481. X    {
  1482. X        bcopy ((char *) &term_settings, (char *) &term, 
  1483. X                                                sizeof (struct sgttyb));
  1484. X        term.sg_flags |= CBREAK | LCASE;
  1485. X
  1486. X        (void) ioctl (0, TIOCSETP, &term);
  1487. X    }
  1488. X#endif BSD
  1489. X
  1490. X    /* ...wait for a 'y' or and 'n' to be typed... */
  1491. X    do
  1492. X    {
  1493. X    } while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
  1494. X            (j == 1 && c != 'y' && c != 'n'));
  1495. X
  1496. X    /* ...reset the terminal state... */
  1497. X    
  1498. X    if (set == 0)
  1499. X    {
  1500. X#if defined(SYSV) || defined(UNISOFTV)
  1501. X        (void) ioctl (0, TCSETA, &term_settings);
  1502. X#endif SYSV
  1503. X
  1504. X#ifdef BSD
  1505. X        (void) ioctl (0, TIOCSETN, &term_settings);
  1506. X#endif BSD
  1507. X    }
  1508. X
  1509. X    (void) printf ("\n");
  1510. X    
  1511. X    /* ...and return 0 or 1 to the calling program depending on which
  1512. X       key was pressed (return 2 on some sort of error) */
  1513. X       
  1514. X    if (c == 'y')
  1515. X        exit (0);
  1516. X        else
  1517. X        if (c == 'n')
  1518. X            exit (1);
  1519. X        else
  1520. X            exit (2);
  1521. X    }
  1522. X}
  1523. X
  1524. X/*
  1525. X                            *****************
  1526. X                            *        *
  1527. X                            *   ALARMCALL    *
  1528. X                            *        *
  1529. X                            *****************
  1530. X-------------------------------------------------------------------------
  1531. X| SIGALRM signal handler.  Used to add a timeout facility to gs.        |
  1532. X-------------------------------------------------------------------------
  1533. X*/
  1534. X
  1535. Xstatic int AlarmCall ()
  1536. X{
  1537. X    alarm_gone_off = 1;
  1538. X
  1539. X#ifdef BSD
  1540. X    if (env)
  1541. X        longjmp (env, 1);
  1542. X#endif BSD    
  1543. X}
  1544. X
  1545. X/*
  1546. X                            *****************
  1547. X                            *        *
  1548. X                            *  RESETTERM    *
  1549. X                            *        *
  1550. X                            *****************
  1551. X-------------------------------------------------------------------------
  1552. X| Handler for every other type of signal (that is catchable).  If the     |
  1553. X| terminal state has been fiddled with, reset it then reset the signal    |
  1554. X| to its default state and send the signal again.                       |
  1555. X| Note: The code will work correctly for signals that don't kill the    |
  1556. X        process (may fix it one day, but it's only a minor problem).    |
  1557. X-------------------------------------------------------------------------
  1558. X*/
  1559. X
  1560. Xstatic int ResetTerm (sig)
  1561. Xint sig;
  1562. X{
  1563. X    if (set == 0)
  1564. X    {
  1565. X#if defined(SYSV) || defined(UNISOFTV)
  1566. X    (void) ioctl (0, TCSETA, &term_settings);
  1567. X#endif SYSV
  1568. X
  1569. X#ifdef BSD
  1570. X    (void) ioctl (0, TIOCSETP, &term_settings);
  1571. X#endif BSD
  1572. X    }
  1573. X
  1574. X    (void) signal (sig, old_sig[sig]);
  1575. X
  1576. X    (void) kill (getpid (), sig);
  1577. X}
  1578. END_OF_FILE
  1579. if test 9705 -ne `wc -c <'textmode.c'`; then
  1580.     echo shar: \"'textmode.c'\" unpacked with wrong size!
  1581. fi
  1582. # end of 'textmode.c'
  1583. fi
  1584. if test -f 'yorn.1' -a "${1}" != "-c" ; then 
  1585.   echo shar: Will not clobber existing file \"'yorn.1'\"
  1586. else
  1587. echo shar: Extracting \"'yorn.1'\" \(5595 characters\)
  1588. sed "s/^X//" >'yorn.1' <<'END_OF_FILE'
  1589. X.TH YORN 1 "3 October 1988" "X Version 11"
  1590. X.SH NAME
  1591. Xyorn \- display a dialogue box
  1592. X.SH SYNOPSIS
  1593. X.B yorn
  1594. X[
  1595. X.B -z
  1596. X] 
  1597. X[
  1598. X.B -standard X Toolkit options \.\.\.
  1599. X] "\fBTITLE\fP"
  1600. X.B text to be displayed
  1601. X.SH DESCRIPTION
  1602. X.I Yorn
  1603. Xis a utility that asks the user a question that can be answered yes or no.  It
  1604. Xdisplays a question mark symbol, some justified text and two buttons labelled
  1605. Xwith a tick and a cross, representing yes or no respectively.  The question
  1606. Xcan be answered by clicking one of the boxes with the mouse.
  1607. X.PP
  1608. XIf the connection to the X server cannot be established, the title and text is
  1609. Xprinted on \fIyorn\fP's standard output and the user is requested to press
  1610. X\fIY\fP or \fIN\fP to answer the question.
  1611. X.PP
  1612. X.I Yorn
  1613. Xcan take the following option:
  1614. X.TP 8
  1615. X.B \-z
  1616. XNo Zoom.  The window will attempt to by pass the window manager and appear
  1617. Ximmediately, rather than going through the window manager's placement and
  1618. Xsizing scheme.
  1619. X.PP
  1620. X\fIyorn\fP additionally recognizes the following standard X Toolkit command
  1621. Xline arguments:
  1622. X.TP 8
  1623. X.B \-bg \fIcolour\fP \fRor\fP \-background \fIcolour\fP
  1624. XThis option specifies the colour to use for the background of the window and
  1625. Xwidgets.  The default is `white.'
  1626. X.TP 8
  1627. X.B \-bd \fIcolour\fP \fRor\fP \-bordercolor \fIcolour\fP
  1628. XThis option specifies the colour to use for the border of the main window.
  1629. XThe default is `black.'
  1630. X.TP 8
  1631. X.B \-bw \fInumber\fP \fRor\fP \-borderwidth \fInumber\fP
  1632. XThis option specifies the width in pixels of the border surrounding the main
  1633. Xwindow. 
  1634. X.TP 8
  1635. X.B \-fg \fIcolour\fP \fRor\fP \-foreground \fIcolour\fP
  1636. XThis option specifies the colour to use for all text and symbols.  The default
  1637. Xis `black'.
  1638. X.TP 8
  1639. X.B \-fn \fIfont\fP
  1640. XThis option specifies the font to be used for displaying the text warning
  1641. Xmessage.  The default is `serif10'.
  1642. X.TP 8
  1643. X.B \-name \fIname\fP
  1644. XThis option specifies the application name under which resources are to be
  1645. Xobtained, rather than the default executable file name, `yorn'.
  1646. X.TP 8
  1647. X.B \-geometry \fIgeometry\fP
  1648. XThis option specifies the preferred size and position yorn window; see
  1649. X\fIX(1)\fP; 
  1650. X.TP 8
  1651. X.B \-display \fIdisplay\fP
  1652. XThis option specifies the X server to contact; see \fIX(1)\fP.
  1653. X.TP 8
  1654. X.B \-xrm \fIresourcestring\fP
  1655. XThis option specifies a resource string to be used.  This is especially
  1656. Xuseful for setting resources that do not have separate command line options.
  1657. X.SH "X DEFAULTS"
  1658. X\fIYorn\fP is implemented using the Athena widgets.  Each widget can
  1659. Xindividually or in groups have various visual and operational aspects changed
  1660. Xvia a `.Xdefaults' file on the client machine or the `RESOURCE_MANAGER'
  1661. Xproperty on the server.  All widgets have a common set of resources
  1662. X(background, backgroundPixmap, etc.) and resources unique to each type of
  1663. Xwidget; a `command button' widget, for example, also has a cursor resource.
  1664. XFor a full list see the document \fIX Toolkit Widgets - C Language X Interface\fP.
  1665. X.PP
  1666. XThe path names and types of all widgets used by \fIyorn\fP are as follows:
  1667. X.TP 8
  1668. X.B "\fIXXX\fP.alert/yorn"
  1669. XThe widget that is a child of root.  All the other widgets used by the yorn
  1670. Xbox are children or grand children of this widget. 
  1671. X.TP 8
  1672. X.B "\fIXXX\fP.alert/yorn.contents"
  1673. XA form widget that manages the layout of the yorn box.  Normally completely
  1674. Xcovers the `alert/yorn' widget.
  1675. X.TP 8
  1676. X.B "\fIXXX\fP.alert/yorn.contents.symbol"
  1677. XA widget to display the `query' symbol.
  1678. X.TP 8
  1679. X.B "\fIXXX\fP.alert/yorn.contents.ok/yes button"
  1680. XA command button widget to obtain a `yes' answer from the user, normally
  1681. Xdisplaying a `tick' symbol.
  1682. X.TP 8
  1683. X.B "\fIXXX\fP.alert/yorn.contents.no button"
  1684. XA command button widget to obtain a `no' answer from the user, normally
  1685. Xdisplaying a `cross' symbol.
  1686. X.TP 8
  1687. X.B "\fIXXX\fP.alert/yorn.contents.message"
  1688. XA widget to display and format the text message.
  1689. XThe `\fIXXX\fP' may be replaced by either \fIyorn\fP's classname, `Xopentop',
  1690. Xor its application name, `yorn'.
  1691. X.PP
  1692. XAdditionally, the following items are also fetched from the resource database:
  1693. X.TP 8
  1694. X.B "yornsym"
  1695. XThe pathname of a bitmap file to use as an alternative to the
  1696. X`question-mark-in-a-triangle' symbol displayed in the `symbol' widget.
  1697. X.TP 8
  1698. X.B "ticksym"
  1699. XThe pathname of a bitmap file to use as an alternative to the `tick' symbol
  1700. Xdisplayed in the `ok/yes button' widget.
  1701. X.TP 8
  1702. X.B "crosssym"
  1703. XThe pathname of a bitmap file to use as an alternative to the `cross' symbol
  1704. Xdisplayed in the `no button' widget.
  1705. X.TP 8
  1706. X.B "backgroundPixmap.foreground"
  1707. XOne of two colours (the other is the widget's background colour) required when
  1708. Xconverting a bitmap file into a pixmap for use as the widget's background
  1709. Xpixmap. 
  1710. X.SH RETURN CODES
  1711. X.IP
  1712. X0 \- Termination via the tick box.
  1713. X.IP
  1714. X1 \- Termination via the cross box.
  1715. X.IP
  1716. X2 \- Termination due to some internal error.
  1717. X.SH ENVIRONMENT
  1718. X.TP 8
  1719. XDISPLAY - the default host and display number of the X server.
  1720. X.TP 8
  1721. XXENVIRONMENT - the name of the Xdefaults file to use (normally 
  1722. X$HOME/.Xdefaults).
  1723. X.SH EXAMPLES
  1724. X.IP
  1725. Xyorn "Yorn" "The file /etc/passwd exists.  Are you sure you want to delete it ?"
  1726. X.PP
  1727. XWill open an yorn box with the title
  1728. X.I Yorn
  1729. Xand containing the text
  1730. X.I The file /etc/passwd exists.  Are you sure you want to delete it ?
  1731. Xand waits for the user to click one of the buttons.
  1732. X.SH FILES
  1733. X$HOME/.Xdefaults
  1734. X/usr/lib/X11/app-defaults/Xopentop
  1735. X.SH SEE ALSO
  1736. Xalert(1), gs(1)
  1737. X.SH BUGS
  1738. X.PP
  1739. XIf the font is too large or the message too long, the text will be clipped.
  1740. X.PP
  1741. XThe title may not be displayed if the window manager does not provide title bars
  1742. Xaround windows or the \fB\-z\fP option is used.
  1743. X.SH AUTHOR
  1744. XGary Henderson & Mark E. Howells, Torch Computers Ltd.
  1745. END_OF_FILE
  1746. if test 5595 -ne `wc -c <'yorn.1'`; then
  1747.     echo shar: \"'yorn.1'\" unpacked with wrong size!
  1748. fi
  1749. # end of 'yorn.1'
  1750. fi
  1751. echo shar: End of archive 3 \(of 4\).
  1752. cp /dev/null ark3isdone
  1753. MISSING=""
  1754. for I in 1 2 3 4 ; do
  1755.     if test ! -f ark${I}isdone ; then
  1756.     MISSING="${MISSING} ${I}"
  1757.     fi
  1758. done
  1759. if test "${MISSING}" = "" ; then
  1760.     echo You have unpacked all 4 archives.
  1761.     rm -f ark[1-9]isdone
  1762. else
  1763.     echo You still need to unpack the following archives:
  1764.     echo "        " ${MISSING}
  1765. fi
  1766. ##  End of shell archive.
  1767. exit 0
  1768. -- 
  1769. Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
  1770. Moderator of comp.sources.x
  1771.